package com.googlecode.cswish.service;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

import com.googlecode.cswish.struts.spring.generator.GeneratorHelper;
import com.opensymphony.xwork2.ActionSupport;

/**
 * A dummy action class for "Bytecode"
 * 	 
 * @author Jerry.feng Date: 2008-9-10
 */
public class VOObject extends ActionSupport implements Map {
	
	private String _prepare;
	
	private String f1;
	
	private boolean f2;
	
	private String bizMethod;

	public VOObject() {
		
	}
	
	public String getF1() {
		return f1;
	}
	
	public String getF2() {
		return f1;
	}
	
	public String getF3() {
		return f1;
	}
	
	public String getF4() {
		return f1;
	}
	
	public String getF5() {
		return f1;
	}

	public void setF1(String f1) {
		this.f1 = f1;
	}
	
	public void setF2(boolean f2) {
		this.f2 = f2;
	}
	
	public String bizMehothod() {
		if ("true".equals(this._prepare)) {
			return "input";
		}
		
		// instance the biz object
		BizTestService biz = (BizTestService)GeneratorHelper.create(BizTestService.class);
		// mock a business method call
		bizMethod = biz.test2(this.f1, this.f2);
		return "success";
	}
	
	public void bizMehothod2() {
		// instance the biz object
		BizTestService biz = (BizTestService)GeneratorHelper.create(BizTestService.class);
		// mock a business method call
		bizMethod = biz.test2(this.f1, this.f2);
	}
	
	public Collection<String> test(Map<String, String> values) {
		values.put("a", "b");
		return values.values();
	}

	public Object get(Object key) {
		String sKey = (String) key;
		String methodName = "get" + 
			Character.toUpperCase(sKey.charAt(0)) + sKey.substring(1);
		
		Object result = null;
		if ("getF1".equals(methodName)) {
			result = getF1();
		}
		else if ("getF2".equals(methodName)) {
			result = getF2();
		}
		else if ("getF3".equals(methodName)) {
			result = getF3();
		}
		else if ("getF4".equals(methodName)) {
			result = getF4();
		}
		else if ("getF5".equals(methodName)) {
			result = getF5();
		}

		// more invoker
		return result;
	}
	
	
	public Object put(Object key, Object value) {
		String sKey = (String) key;
		String methodName = "set" + 
			Character.toUpperCase(sKey.charAt(0)) + sKey.substring(1);
		
		Object result = null;
		Object convertedValue = null;
		if ("setF1".equals(methodName)) {
			System.out.println(methodName);
			
			convertedValue = GeneratorHelper.convert(value, String.class);
			convertedValue = GeneratorHelper.convert(value, boolean.class);
			
			setF1((String) convertedValue);
			System.out.println("end");
			
			convertedValue = (Boolean) convertedValue;
			setF2((Boolean) convertedValue);
		}
		
		// more invoker
		return null;
	}
	
	public void clear() {
	}
	
	public boolean containsKey(Object key) {
		if ("f1".equals(key)
				|| "f2".equals(key)
				|| "f3".equals(key)) {
			return true;
		}
		return false;
	}
	
	public boolean containsValue(Object value) {
		return false;
	}
	
	public Set entrySet() {
		return null;
	}
	
	public boolean isEmpty() {
		return false;
	}
	
	public Set keySet() {
		return null;
	}
	
	public void putAll(Map m) {
	}
	
	public Object remove(Object key) {
		return null;
	}

	public int size() {
		return 0;
	}

	public Collection values() {
		return null;
	}
}
